<?
// Navi
$linkarray=$content->orderby('position')->contmedlinks->as_array();

if(! isset($maxw)){
	$maxw=$content->var1;
}

if(! isset($maxh)){
	$maxh=$content->var2;
}

if($maxw==''){
	$maxw=1000;
}
if($maxh==''){
	$maxh=100;
}

$maxwbig=700;
$maxhbig=700;



if(count($linkarray)==0){
	return;
}


$selectedind=0;
$count=0;


echo '<div class="medialist" >';
$count=0;

foreach ($linkarray as $link){
	$media=$link->media;
		
	$url=$media->get_resized_url($maxw,$maxh);
	$bigurl=$media->get_resized_url($maxwbig, $maxhbig);
	$bigurlarray[]=url::base().$bigurl;
	
	
	echo '<div class="mediaelm" index="'.$count.'">';
	echo html::image($url);	
	echo '</div>';
	$count++;
}
echo '<div class="clear"></div>';
echo '</div>';

?>

<script type="text/javascript">

$(document).ready(function()
{
	var bigurlarray=new Array("<?= implode('","',$bigurlarray)?>");
	var index=0;
	
 	$(".mediaelm").click(function(e) 
	 {
		 index=Number( $(this).attr("index"));
		 $("#media_overlay").fadeIn(100);
		 chooseelmbyind(index);
	 });
 
 
 	$(".close").click(function(e)
	{
		e.preventDefault();
		$("#media_overlay").fadeOut(100);
	})
	
	
	$("#media_overlay .media").click(function(e)
	{
		e.preventDefault();
		
		index+=1;
		if(index>bigurlarray.length-1){
			index=0;	
		}
		chooseelmbyind(index);
	
	
	})
	
	$(".next").click(function(e)
	{
		e.preventDefault();
		
		index+=1;
		if(index>bigurlarray.length-1){
			index=0;	
		}
		chooseelmbyind(index);
	
	
	})
	
	$(".prev").click(function(e)
	{
		e.preventDefault();
		
		index-=1;
		if(index<0){
			index=bigurlarray.length-1;
			
		}
		chooseelmbyind(index);
	})
	
	function chooseelmbyind(ind){
		$('#media_overlay .media').html('<img src="'+bigurlarray[index]+'" />');
	}
	
 
});


</script>
<?
/*

<script type='text/javascript'><!--
$(document).ready(function()
{
	<?
	echo "var id=".$content->id.";"; 
	echo $js_array;
	?>					   
						   
	
	$('.img_link_'+id).click(function(){
		//alert("hi");
		var index = $(this).attr('index');
		
		$("#media_overlay").show();
		<? 
		echo "var top=$('#".$content->id."').position().top;";
		echo"current_index=index;
		";
		echo"img_array = img_array_".$content->id.";
		";
		echo"img_height_array = img_height_array_".$content->id.";
		";
		echo "var imgstr = img_array_".$content->id."[index];
		";
		?>
		//alert(top);
		$("#img_container").css('top',(top+200)+"px");
		$("#img_holder").css('height','auto');
		$("#img_holder").html(imgstr);
		//-------------------------------------CHECKIMGNAV 
		$('#prev_img').show();
        $('#next_img').show();
        $('#next_img_off').hide();
        $('#prev_img_off').hide();
        if(current_index==0){
            $('#prev_img').hide();
            $('#prev_img_off').show();
        }
        if(current_index==(img_array.length-1)){
            $('#next_img').hide();
            $('#next_img_off').show();
        }
		//--------------------------------------
		
		
	
	});
	
	
	
});

--></script>
*/
?>


